package com.hanoi.wiki.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.hanoi.wiki.model.json.BlocksJson;

@Entity
@Table(name = "BLOCKS")
public class Blocks implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Blocks() {
		
	}
	
	public Blocks(BlocksJson json) {
		this.latitue 		= json.getLatitue();
		this.longtitue		= json.getLongtitue();		
		this.description	= json.getDescription();
		this.range			= json.getRange();
	}
	
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

	@Column(name = "LONGTITUE")
	private Float longtitue;

	@Column(name = "LATITUE")
	private Float latitue;

	@Column(name = "RANGES")
	private Float range;

	@Column(name = "DESCRIPTION", length = 2000)
	private String description;

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "BLOCKS_COORDINATES", joinColumns = { @JoinColumn(name = "BLOCK_ID") }, inverseJoinColumns = { @JoinColumn(name = "COOR_ID") })
	private List<Coordinates> coordinates;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Float getLongtitue() {
		return longtitue;
	}

	public List<Coordinates> getCoordinates() {
		return coordinates;
	}

	public void setCoordinates(List<Coordinates> coordinates) {
		this.coordinates = coordinates;
	}

	public void setLongtitue(Float longtitue) {
		this.longtitue = longtitue;
	}

	public Float getLatitue() {
		return latitue;
	}

	public void setLatitue(Float latitue) {
		this.latitue = latitue;
	}

	public Float getRange() {
		return range;
	}

	public void setRange(Float range) {
		this.range = range;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
